package com.larry.isn;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

public class LarryFileReader {

	private FileInputStream fis;

	private BufferedInputStream bis;

	private DataInputStream dis;

	public LarryFileReader(File file) {
		this.init(file);
	}

	@SuppressWarnings("deprecation")
	public List<String> read() throws Exception {
		List<String> list = new ArrayList<String>();
		try {
			while (dis.available() != 0) {
				String line = dis.readLine();
				if ("".equals(line)) {
					continue;
				}
				list.add(line);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			this.closeReader();
		}
		return list;
	}

	private void init(File file) {
		try {
			if (!file.exists()) {
				file.createNewFile();
			}
			fis = new FileInputStream(file);
			bis = new BufferedInputStream(fis);
			dis = new DataInputStream(bis);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void closeReader() throws Exception {
		dis.close();
		bis.close();
		fis.close();
	}
}
